<?php
	
	function dbconnect() 
	{ 
		include('config.php'); 
		static $connect = null; 
		if ($connect === null) 
			{
				 $connect =  mysql_connect($host, $user, $passwd) or die(mysql_error());
				 mysql_query("SET character_set_results=utf8", $connect);
				 mysql_select_db($database); 
			} 
		return $connect; 
	} 
	
	
	
	function getid_auto_increment()
	{
		
		$r= mysql_query("SHOW TABLE STATUS LIKE 'Hoa_don_nhap'",dbconnect());
		$row = mysql_fetch_array($r); 
        $n = $row['Auto_increment']; 
        return $n;
		
		} 
	function getbyall_ncc()
	{ 
		$allnxb_req = mysql_query("SELECT * FROM Nha_cung_cap" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 

	function getbyall_sach()
	{ 
		$allnxb_req = mysql_query("SELECT * FROM sach" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 
	} 
	
	function insert_hoadonnhap($cd, $tt) 
			{ 
	 
		$query= mysql_query("INSERT INTO hoa_don_nhap SET ID_Nha_cung_cap=N'".$cd['ID_Nha_cung_cap']."', Thoi_gian= NOW(), Tong_tien=N'".$tt."'  ", dbconnect());  
		
			}
	function maxid_hoadonnhap()
	{
		$allnxb_req = mysql_query("SELECT MAX(ID) FROM Hoa_don_nhap" ,dbconnect()); 
		$result = array(); 
		while ($nxb = mysql_fetch_array($allnxb_req))
		 { 
			$result[] = $nxb; 
		 } 
		return $result; 

	}
		
	function chi_tiet_nhap($idsach, $soluong, $idhoadonnhap, $gianhap, $thanhtien)
	{
		$query = mysql_query("INSERT INTO chi_tiet_nhap SET ID_Sach = N'".$idsach."', So_luong = N'".$soluong."', ID_Hoa_don_nhap=N'".$idhoadonnhap."',  Gia_nhap=N'".$gianhap."', Thanh_tien=N'".$thanhtien."' ");
		}
	
?>